// custom-tab-bar/index.ts
Component({
  /**
   * 组件的属性列表
   */
  properties: {

  },

  /**
   * 组件的初始数据
   */
  data: {
    show: false,  // 添加显示
    selected: 0,  // 选中的菜单的下标
    color: "#a5b5b5",
    selectedColor: "#2c9678",
    list: [{
      "pagePath": "/pages/tabbar/home/index",
      "text": "首页",
      "iconPath": "/assets/images/home.png",
      "selectedIconPath": "/assets/images/home-select.png"
    }, {
      "pagePath": "/pages/tabbar/detail/index",
      "text": "明细",
      "iconPath": "/assets/images/detail.png",
      "selectedIconPath": "/assets/images/detail-select.png"
    }, {
      "pagePath": "/pages/tabbar/detail/index",
      "text": "添加",
      "iconPath": "/assets/images/add.png",
      "selectedIconPath": "/assets/images/add.png"
    },
    {
      "pagePath": "/pages/tabbar/statistics/index",
      "text": "统计",
      "iconPath": "/assets/images/statistics.png",
      "selectedIconPath": "/assets/images/statistics-select.png"
    },
    {
      "pagePath": "/pages/tabbar/my/index",
      "text": "我的",
      "iconPath": "/assets/images/my.png",
      "selectedIconPath": "/assets/images/my-select.png"
    }]
  },

  /**
   * 组件的方法列表
   */
  methods: <any>{
    switchTab(e: WechatMiniprogram.CustomEvent) {
      const data = e.currentTarget.dataset
      if (data.index === 2) {
        this.setData({ show: true })
        return;
      }
      const url = data.path
      wx.switchTab({ url })
      this.setData({ selected: data.index })
    },
    // 关闭面板
    handleClosePanel() {
      this.setData({ show: false })
    }
  },
})
